﻿using System;
using ZX.Web.UI.Controls;
using ZX.SYS.Bussiness;
using ZX.SYS.Library;
using System.Data;
using System.Text.RegularExpressions;
using System.Configuration;
using System.Text;
using System.IO;
using System.Xml;
using System.Net;
namespace ZX.WebApp.Message
{
    public partial class Mq400 : BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.IsPostBack)
            {
                //string id = Request.QueryString["id"];
                if (Request.QueryString["id"] != null)
                {
                    MQ400Main mm = new MQ400Main();// MQ400Main.Get(new Guid(Request.QueryString["id"]));

                    MmsProccess mp = new MmsProccess();
                    DataTable dt = mp.getmq400detail(new Guid(Request.QueryString["id"]));
                    if (dt.Rows.Count > 0)
                    {
                        txtphone.Value = dt.Rows[0]["cphone"].ToString(); //mm.cphone;//电话     
                        txtcometime.Value = dt.Rows[0]["comeintime"].ToString();// mm.comeintime.ToString("yyyy-MM-dd HH:mm");//来电时间 
                        txtcus.Value = dt.Rows[0]["comename"].ToString();// mm.comename;//客户名称
                        txtzhiwei.Value = dt.Rows[0]["comerole"].ToString();// mm.comerole;//职位
                        txtcompany.Value = dt.Rows[0]["company"].ToString();// mm.company;//企业名称
                        txtcomesource.Value = dt.Rows[0]["cfrom"].ToString();// mm.cfrom;//客户来源
                        txtcusrequere.Value = dt.Rows[0]["crequery"].ToString();// mm.crequery;//客户需求
                        txtjiedianren.Value = dt.Rows[0]["recname"].ToString();// mm.recname;//接电人
                        txtprocp.Value = dt.Rows[0]["procname"].ToString();// mm.procname;//处理人
                        txttelphone.Value = dt.Rows[0]["procphone"].ToString();
                        hdfdeptid.Value = dt.Rows[0]["procdeptid"].ToString();
                        txtprocdept.Value = dt.Rows[0]["procdept"].ToString();// mm.procdept;//处理部门
                        txtproctime.Value = dt.Rows[0]["procdate"].ToString();// mm.procdate.ToString("yyyy-MM-dd HH:mm");//处理时间
                        txtstepresult.Value = dt.Rows[0]["stepresult"].ToString();// mm.stepresult;//阶段成果
                        rbtoverstep.SelectedValue = dt.Rows[0]["overresult"].ToString();// mm.overresult;//最终结果
                        selecttype.SelectedValue = dt.Rows[0]["typeid"].ToString();
                        txtreqtype.Value = dt.Rows[0]["creqtype"].ToString();
                        //if (dt.Rows[0]["adduser"].ToString() == User.UserID.ToString() || User.LoginName.ToLower()=="admin")
                        //{
                        //    if (dt.Rows[0]["overresult"].ToString() == "未处理")
                        //        btndelete.Visible = true;
                        //}
                    }
                        
                }
                else
                {
                    txtjiedianren.Value = User.UName;
                    //labadduser.Text = User.UName;
                }
                
            }
        }

        protected void btnsaveOnClick(object sender, EventArgs e)
        {
            MQ400Main mm = new MQ400Main();
            
            mm.cphone = txtphone.Value;//电话     
            mm.comeintime =Convert.ToDateTime(txtcometime.Value);//来电时间 
            mm.comename = txtcus.Value;//客户名称
            mm.comerole = txtzhiwei.Value;//职位
            mm.company = txtcompany.Value;//企业名称
            mm.cfrom = txtcomesource.Value;//客户来源
            mm.crequery = txtcusrequere.Value;//客户需求
            mm.recname = txtjiedianren.Value;//接电人
            mm.procname = txtprocp.Value;//处理人
            if (procp.Value!="")
                mm.procid =new Guid(procp.Value);
            mm.procphone= txttelphone.Value;// = dt.Rows[0]["procphone"].ToString();
            mm.procdept = txtprocdept.Value;//处理部门
            if (hdfdeptid.Value!="")
                mm.procdeptid = new Guid(hdfdeptid.Value);
            mm.procdate = txtproctime.Value;//处理时间
            mm.stepresult = txtstepresult.Value;//阶段成果
            mm.overresult = rbtoverstep.SelectedValue;//最终结果
            mm.typeid = selecttype.SelectedValue;
            mm.typename = selecttype.SelectedItem.Text;
            mm.creqtype = txtreqtype.Value;
            if (Request.QueryString["id"] == null || Request.QueryString["id"]=="")
            {
                mm.mq4id = Guid.NewGuid();//ID
                mm.adduser = User.UserID;
                mm.addtime = DateTime.Now;
                mm.Insert();
            }
            else
            {
                mm.mq4id = new Guid(Request.QueryString["id"]);
                mm.Update();
            }

            Label1.Text = "保存成功";
            ClientScript.RegisterStartupScript(this.GetType(), "script2", "<script>function refreshresult(){parent.ReLoadData();};</script>");
        }

        protected void btnDeleteOnClick(object sender, EventArgs e)
        {
            MmsProccess mm = new MmsProccess();
            if (mm.deletemq400(Request.QueryString["id"]) > 0)
            {
                Label1.Text = "删除成功";
                btnsave.Enabled = false;
                btndelete.Enabled = false;
                //ClientScript.RegisterStartupScript(this.GetType(), "script1", "<script>backresult('1');</script>");

                //Response.Write("<script>alert(\"删除成功\");window.opener = null;window.close();</script>");
            }
        }


    }
}